package cn.tedu.csmall.server.controller;

import cn.tedu.csmall.server.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 类别控制器
 */
//@Controller
//@ResponseBody  //"响应正文"模式
@RestController
@RequestMapping("/categories")
public class CategoryController {

    @Autowired
    public ICategoryService categoryService;

    public CategoryController(){
        System.out.println("类别控制器:CategoryController");
    }

    // 访问 localhost:8080/categories/add-new
    // @GetMapping("/add-new")
    // @PostMapping("/add-new")
    @RequestMapping("/add-new")
    public String addNew(){
        System.out.println("CategoryController.addNew()");
        return "add-new";
    }

    // 访问 localhost:8080/categories/delete
    @RequestMapping("/{id}/delete")
    public String delete(@PathVariable Long id){
        System.out.println("CategoryController.delete()");
        System.out.println("根据id="+id+"删除类别");
        return "del";
    }

    @RequestMapping("/{id}/update")
    public String edit(@PathVariable Long id){
        System.out.println("CategoryController.edit()");
        System.out.println("根据id="+id+"修改类别");
        return "update";
    }

    @GetMapping
    public String list(){
        System.out.println("CategoryController.list()");
        return "list";
    }


}





